﻿Imports System.Windows.Media
Imports System.Windows.Data
Imports System.Windows

Public Class GlossyStyleConverter
    Implements IValueConverter

    Public Function Convert(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.Convert
        If targetType IsNot GetType(Brush) Then _
            Throw New InvalidOperationException("La cible doit être de type System.Window.Media.Brush")
        Try
            Dim colBase As SolidColorBrush = CType(value, SolidColorBrush)
            Dim brshResult As New LinearGradientBrush
            brshResult.StartPoint = New System.Windows.Point(0.5, 0)
            brshResult.EndPoint = New System.Windows.Point(0.5, 1)
            Dim colDegrade1 As Color = Color.FromArgb(50, colBase.Color.R, colBase.Color.G, colBase.Color.B)
            Dim colDegrade2 As Color = Color.FromArgb(160, colBase.Color.R, colBase.Color.G, colBase.Color.B)
            Dim colDegrade3 As Color = Color.FromArgb(190, colBase.Color.R, colBase.Color.G, colBase.Color.B)
            Dim colDegrade4 As Color = Color.FromArgb(210, colBase.Color.R, colBase.Color.G, colBase.Color.B)
            brshResult.GradientStops.Add(New GradientStop(colDegrade1, 0))
            brshResult.GradientStops.Add(New GradientStop(colDegrade2, 0.5))
            brshResult.GradientStops.Add(New GradientStop(colDegrade3, 0.5))
            brshResult.GradientStops.Add(New GradientStop(colDegrade4, 1))
            Return brshResult
        Catch ex As Exception
            Return DependencyProperty.UnsetValue
        End Try
    End Function

    Public Function ConvertBack(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.ConvertBack
        Throw New NotImplementedException()
    End Function
End Class
